home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 …SCII & the Runetime Code / ADC Developer CD (1992-07) (''Butch ASCII And The Runtime Code'')_iso / Dev.CD 199207.iso / Developer Essentials / DTS Sample Code / Macintosh Sample Code / SC.001.Sample / Sample.inc1.a < prev    next >
Encoding:
Text File  |  1992-06-02  |  13.3 KB  |  381 lines  |  [TEXT/MPS ]

  1. *
  2. *    Apple Macintosh Developer Technical Support
  3. *
  4. *    MultiFinder-Aware Simple Sample Application
  5. *
  6. *    Sample
  7. *
  8. *    Sample.inc1.a    -    Assembler Source
  9. *
  10. *    Copyright © 1989 Apple Computer, Inc.
  11. *    All rights reserved.
  12. *
  13. *    Versions:    
  14. *        1.00            08/88
  15. *        1.01            11/88
  16. *        1.02            04/89
  17. *        1.03            06/89
  18. *        1.04            06/92
  19. *
  20. *    Components:
  21. *        Sample.p        June 1, 1989
  22. *        Sample.c        June 1, 1989
  23. *        SampleInit.c        June 2, 1992
  24. *        Sample.a        June 1, 1989
  25. *        Sample.inc1.a        June 1, 1989
  26. *        SampleMisc.a        June 1, 1989
  27. *        Sample.r        June 1, 1989
  28. *        Sample.h        June 1, 1989
  29. *        PSample.make        June 1, 1989
  30. *        CSample.make        June 1, 1989
  31. *        ASample.make        June 1, 1989
  32. *        CSample.π        June 2, 1992
  33. *        CSample.π.rsrc        June 2, 1992
  34. *
  35. *    Sample is an example application that demonstrates how to
  36. *    initialize the commonly used toolbox managers, operate 
  37. *    successfully under MultiFinder, handle desk accessories, 
  38. *    and create, grow, and zoom windows.
  39. *
  40. *    It does not by any means demonstrate all the techniques 
  41. *    you need for a large application. In particular, Sample 
  42. *    does not cover exception handling, multiple windows/documents, 
  43. *    sophisticated memory management, printing, or undo. All of 
  44. *    these are vital parts of a normal full-sized application.
  45. *
  46. *    This application is an example of the form of a Macintosh 
  47. *    application; it is NOT a template. It is NOT intended to be 
  48. *    used as a foundation for the next world-class, best-selling, 
  49. *    600K application. A stick figure drawing of the human body may 
  50. *    be a good example of the form for a painting, but that does not 
  51. *    mean it should be used as the basis for the next Mona Lisa.
  52. *
  53. *    We recommend that you review this program or TESample before 
  54. *    beginning a new application.
  55.  
  56. * ----------- DEBUGGING INFORMATION -------------
  57. * This is used as a global switch to turn off the generation of debugging information.
  58. * The MACRO "DbgInfo" will generate this debugging information if set to 1.
  59.  
  60. DebuggerInfo    EQU    1
  61.  
  62.  
  63. * ================================================
  64. * --------   MACRO DEFINITIONS SECTION  ----------
  65. * ================================================
  66.  
  67. * ------------- GENERATE A PASCAL "CASE" OR "IF" SEQUENCE -------------
  68. * The following macro is used to generate a branch based on an index value
  69. * in a D-register with a value from 0 to N.  The branch is through a table
  70. * of relative addresses also generated by this macro. The macro is called
  71. * in one of two forms as follows:
  72.  
  73. *  {Form #1}    Case#        (Dreg,Default),case0,case1,...caseN
  74. *  {Form #2}    Case#.<size>    (Dreg,IF),(cst0,case0),...,(cstN,caseN)
  75.  
  76. * In Form #1, the "Default" specifies a label for any omitted case labels not
  77. * specified explicitly. The "case0", "case1",..."caseN" are case labels
  78. * identifying the various cases to be processed.  A case label may be omitted,
  79. * in which case the "Default" is used. The "Default" may also be omitted, but
  80. * in that case all case labels must be specified. If there are fewer case labels
  81. * than there are cases, but there are N possible values for the case index, the
  82. * proper number of trailing commas must be supplied to generate the defaults.
  83.  
  84. * In Form #2, the default is specified as the word "IF".  In this form the macro
  85. * generates a set of compares (CMPI's) and branches (BEQ) for each specified
  86. * case (there is no implicit default).    Each case is a constant/label pair.
  87. * The constant is compared (CMPI.W) and an branch is done (BEQ) to the case if
  88. * the Dreg equals the constant.  A size may be specified for all the branches
  89. * as a <size> attribute to the Case# call itself.  This must either be an "S"
  90. * or "W" to generate BEQ.S's or BEQ.W's.  The default is for "S".
  91.  
  92.         MACRO
  93.         Case#.&Size     &IdxDef
  94.         PRINT        Push,NoMDir     ; only list generated code
  95.         LCLA        &i        ; index to macro parameters
  96.         LCLA        &n        ; total number of macro parameters
  97.         LCLC        &Dreg,&Def    ; the Dreg and Default parameters
  98.         LCLC        &sz         ; the <size> value
  99.  
  100. &Dreg        SETC        &IdxDef[1]    ; pick off 1st opnd of sublist
  101. &Def        SETC        &IdxDef[2]    ; pick off 2nd opnd of sublist
  102. &n        SETA        &Nbr(&Syslist)    ; done for efficiency
  103. &i        SETA        2        ; cases start at 2nd parameter
  104.  
  105.  IF &UpCase(&Def) <> 'IF' THEN
  106. .* Create the jump table and the index value
  107. * -----------------------------------------------
  108.     ADD         &Dreg,&Dreg
  109.     MOVE        Case&SysNdx(&Dreg),&Dreg
  110.     JMP         Case&SysNdx(&Dreg)
  111.  
  112. Case&SysNdx
  113.     WHILE &i <= &n DO                ; process each case label
  114.        IF &SysList[&i] <> '' THEN
  115.         DC.W        &SysList[&i]-Case&SysNdx
  116.        ELSE
  117.         DC.W        &Def-Case&SysNdx
  118.        ENDIF
  119.        &i: SETA &i+1                 ; count off parameter
  120.     ENDWHILE
  121.  ELSE                            ; process (Cst,lbl) pairs
  122.  
  123. .* Create a series of CMPI and BEQ instructions
  124. * -----------------------------------------------
  125.     &Sz: SETC &Default(&Size, 'S')             ; setup size attribute
  126.     WHILE &i <= &n DO                ; process each (Cst,lbl) pair
  127.        CMPI        #&SysList[&i,1],&Dreg
  128.        BEQ.&Sz     &SysList[&i,2]
  129.        &i: SETA &i+1                ; count off parameter
  130.     ENDWHILE
  131.  ENDIF
  132.  
  133.         PRINT    Pop                 ; restore original print status
  134.         ENDM
  135.  
  136.  
  137. * ------------- GENERATE DEBUGGER SYMBOL INFORMATION -------------
  138. * This Macro will generate information for the debugger to read and display
  139. * as its module name.  This aids in debugging Asm code while looking at it
  140. * in the debugger.  This macro can only work if called at the end of stack
  141. * frame.  The appearance of the Macro statement in the source code must occur
  142. * immediately after the final "JMP   (A0)" or "RTS" instruction following the UNLINK.
  143. * Spaces may be included in the name, but no quotes are allowed.
  144.  
  145. *  {Form #1}    DbgInfo        ModName
  146. *  {Form #2}    DbgInfo.New    Really Long Module Name For MacsBug 6.0
  147.  
  148. * There are now two naming conventions used in MacsBug, Form #1 is the older MacsBug,
  149. * or TMON, and Form #2 is the newer MacsBug 6.0.  The older method would only
  150. * allow for a fixed length of eight characters.  If a shorter name is passed to
  151. * this Macro, it will extend the length to 8 chars with trailing spaces.
  152. * MacsBug 6.0 will now allow for a variable length C type string. This Macro will
  153. * create the proper DC statements and takes into account word alignment issues.
  154.  
  155.  
  156.         MACRO
  157.         DbgInfo.&Opt     &ModName#    ; the name to be used in the Debugger
  158.         PRINT        Push,NoMDir     ; Only list generated code
  159.         LCLC        &DbgName#    ; name to generate for MacsBug
  160.         LCLC        &DbgTemp    ; temporary name variable
  161.         LCLC        &New        ; variable used to test old vs. new
  162.         LCLC        &S        ; variable used to save PRINT state
  163.  
  164.  IF DebuggerInfo THEN                        ; do we want debugging info?
  165.     IF &ModName# ≠ '' THEN                    ; did we get a module name?
  166.     &New: SETC &UpCase(&Opt)                ; make option all upper case
  167.     IF (&New = 'NEW') THEN                    ; do we want new style?
  168.  
  169. .* Create the new MacsBug naming convention
  170. * -----------------------------------------------
  171.        &DbgTemp: SETC    &ModName#            ; generate new type symbols
  172.        IF &Len(&ModName#) < 32 THEN                ; if module name < 32 chars
  173.         IF &Len(&ModName#) // 2 = 0 THEN         ; add space if even so that...
  174.            &DbgTemp: SETC &Concat(&ModName#,' ')     ; string length plus length byte...
  175.         ENDIF                        ; will align to word boundary
  176.        &DbgName#: SETC &Concat(&Chr($80 + &Len(&ModName#)), &DbgTemp)
  177.        ELSE                            ; Length > 32 characters
  178.         IF &Len(&ModName#) // 2 = 1 THEN         ; add space if length is odd
  179.            &DbgTemp: SETC &Concat(&ModName#,' ')
  180.         ENDIF
  181.        &DbgName#: SETC &Concat(&Chr($80), &Chr(&Len(&ModName#)), &DbgTemp)
  182.        ENDIF
  183.     ELSE                            ; make it the older style
  184.  
  185. .* Create the older MacsBug naming convention
  186. * -----------------------------------------------
  187.        IF &Len(&ModName#) < 8 THEN                ; if module name < 8 chars
  188.         &DbgName#: SETC &Concat(&ModName#,'       ')    ; add at least 7 spaces
  189.         &DbgName#: SETC &Concat(&Chr($80 + &ORD(&SubStr(&DbgName#,1,1))), &SubStr(&DbgName#,2,7))
  190.        ELSE                            ; there are at least 8 chars
  191.         &DbgName#: SETC &Concat(&Chr($80 + &ORD(&SubStr(&ModName#,1,1))), &SubStr(&ModName#,2,7))
  192.        ENDIF
  193.     ENDIF
  194.  
  195. .* Create the DC.B with the debugger name, and include the NULs if new MacsBug option
  196. * -----------------------------------------------
  197.     &S: SETC &Setting('STRING')        ; preserve STRING status
  198.     IF &S ≠ 'ASIS' THEN            ; only change it if not already ASIS
  199.        STRING    ASIS
  200.        DC.B      '&DbgName#'
  201.        IF (&New = 'NEW') THEN
  202.         DC.W        0        ; fake literal size for new MacsBug
  203.        ENDIF
  204.        STRING    &S
  205.     ELSE
  206.        DC.B      '&DbgName#'
  207.        IF (&New = 'NEW') THEN
  208.         DC.W        0        ; fake literal size for new MacsBug
  209.        ENDIF
  210.     ENDIF
  211.    ENDIF
  212.  ENDIF
  213.  
  214.         PRINT    Pop             ; restore original print status
  215.         ENDM
  216.  
  217.  
  218. * ================================================
  219. * ---------------  EQUATE SECTION  ---------------
  220. * ================================================
  221.  
  222. * Some various EQUATES we'll use throughout the program.
  223. * -----------------------------------------------
  224. False        EQU    0        ; the value of False
  225. True        EQU    $0100        ; and you thought True = 1, HA!
  226. NIL        EQU    0        ; a NIL pointer to test against
  227.  
  228. ToolTrapBit    EQU    11        ; this bit is on for Tool traps
  229. WaitNextEvent    EQU    $A860        ; the WaitNextEvent trap number
  230. Unimplemented    EQU    $A89F        ; the Unimplemented trap number
  231. EnvironsVersion    EQU    1        ; this is the version of the SysEnvirons we want
  232. SleepValue    EQU    $7FFFFFFF    ; the sleeping time ($7FFFFFFF = MaxLongInt)
  233. SuspendResume    EQU    1        ; the suspend/resume event number of an OSEvent
  234. NoEvents    EQU    0        ; no events mask
  235. ExtremeNeg    EQU    -32768        ; for wide open rects and regions, see AdjustCursor
  236. ExtremePos    EQU    32767-1        ; -1 is because of a bug in regions, see AdjustCursor
  237.  
  238. * This is the minimum result from the following equation:
  239.  
  240. *    applLimit - applZone = minimum heap size
  241.  
  242. * for the application to run. It will insure that enough memory will
  243. * be around for reasonable-sized scraps, FKEYs, etc. to exist with the
  244. * application, and still give the application some 'breathing room'.
  245. * To derive this number, we ran under a MultiFinder partition that was
  246. * our requested minimum size, as given in the 'SIZE' resource.
  247.  
  248. MinHeap        EQU    21*1024        ; minimum heap size in bytes
  249.  
  250. * This is the minimum exceptable result from PurgeSpace, when called
  251. * at initialization time, for the application to run. This number acts
  252. * as a double-check to insure that there really is enough memory for the
  253. * application to run, including what has been taken up already by
  254. * pre-loaded resources, the scrap, code, and other sundry memory blocks.
  255.  
  256. MinSpace    EQU    8*1024        ; minimum stack space in bytes
  257.  
  258.  
  259. * The following equates use for resources.  That's why they have a "r" in front.
  260. * -----------------------------------------------
  261. rMenuBar    EQU    128        ; application's menu bar
  262. rUserAlert    EQU    129        ; error alert for user
  263. rWindow        EQU    128        ; application's window
  264. rAboutAlert    EQU    128        ; about alert
  265. rStopRect    EQU    128        ; rectangle for Stop light
  266. rGoRect        EQU    129        ; rectangle for Go light
  267.  
  268.  
  269. * The following equates are for menu definitions, obviously.
  270. * -----------------------------------------------
  271. AppleMenu    EQU    128        ;  Apple menu
  272. AboutItem    EQU    1
  273.  
  274. FileMenu    EQU    129        ;  File menu
  275. NewItem        EQU    1
  276. OpenItem    EQU    2
  277. CloseItem    EQU    4
  278. SaveItem    EQU    5
  279. SaveAsItem    EQU    6
  280. RevertItem    EQU    7
  281. PageSetupItem    EQU    9
  282. PrintItem    EQU    10
  283. QuitItem    EQU    12
  284.  
  285. EditMenu    EQU    130        ;  Edit menu
  286. UndoItem    EQU    1
  287. CutItem        EQU    3
  288. CopyItem    EQU    4
  289. PasteItem    EQU    5
  290. ClearItem    EQU    6
  291.  
  292. LightMenu    EQU    131        ;  Light menu
  293. StopItem    EQU    1
  294. GoItem        EQU    2
  295.  
  296. * -----------------------------------------------
  297. DITopLeft    EQU    $00500070    ; position of Disk Init dialogs
  298.  
  299. * ================================================
  300. * ----------------  RECORD TYPES  ----------------
  301. * ================================================
  302. * This section is declaring record structures.  These records are
  303. * templates.  No data is allocated at this point.  These are just
  304. * structures, similar to Pascal TYPEs.  They simply generate a list
  305. * of equate offsets.  Since none of these types are defined already
  306. * in the MPW AIncludes, we'll need to define them.
  307.  
  308. * ------------- MOUSE POINT TYPE -------------
  309.  
  310. Point        RECORD    0
  311. v        DS.W    1
  312. h        DS.W    1
  313.         ORG     v
  314. vh        DS.W    h
  315.         ENDR
  316.  
  317. * ------------- RECTANGLE TYPE -------------
  318.  
  319. Rect        RECORD    0
  320. Top         DS.W    1
  321. Left        DS.W    1
  322. Bottom        DS.W    1
  323. Right        DS.W    1
  324.         ORG     Top
  325. TopLeft        DS.L    1
  326. BotRight    DS.L    1
  327.         ENDR
  328.  
  329. * ------------- BITMAP TYPE -------------
  330. * (Defined in QuickEqu.a with MPW 3.2)
  331. *
  332. *BitMap        RECORD    0
  333. *baseAddr    DS.L    1
  334. *rowBytes    DS.W    1
  335. *bounds        DS.L    Rect
  336. *        ENDR
  337.  
  338. * ------------- EVENT RECORD TYPE -------------
  339.  
  340. EventRecord     RECORD    0
  341. What        DS.W    1
  342. Message     DS.L    1
  343. When        DS.L    1
  344. Where        DS.L    Point
  345. Modify        DS.W    1
  346.         ENDR
  347.  
  348. * ------------- THE QUICKDRAW WORLD -------------
  349. * (Defined in QuickEqu.a with MPW 3.2)
  350. *
  351. *QDGlobals    RECORD    0,DECREMENT
  352. *GrafPort     DS.L    1
  353. *White        DS.B    8
  354. *Black        DS.B    8
  355. *Gray        DS.B    8
  356. *LtGray        DS.B    8
  357. *DkGray        DS.B    8
  358. *Arrow        DS.B    cursRec
  359. *ScreenBits    DS.B    BitMap
  360. *RandSeed    DS.L    1
  361. *        ORG     -GrafSize
  362. *        ENDR
  363.  
  364. * ------------- ALL OF OUR GLOBAL DATA -------------
  365. * Note the minimal amount of globals we're using.  Data such as
  366. * the EventRecord, WindowRecords, etc. do not belong in global data
  367. * allocation.  Only data that basically doesn't change through out the
  368. * execution of the program is considered global.  The boolean flags are
  369. * global, since they affect the state of the program at any given time.
  370. * Also note that any appearance of a DS outside of a stack frame will
  371. * be allocated off of A5 and becomes part of global data storage.
  372.  
  373. AppGlobals    RECORD    0        ; this is our global data storage
  374. Stopped        DS.W    1        ; boolean for the state of the light
  375. HasWNEvent    DS.W    1        ; boolean for WaitNextEvent trap, see ForceEnvirons
  376. InBackground    DS.W    1        ; boolean for if in background, see OSEvent
  377. StopRect    DS    Rect        ; rect for the Stop light, set from a resource
  378. GoRect        DS    Rect        ; rect for the Go light, set from a resource
  379. Mac        DS    SysEnvRec    ; the system environment record, see ForceEnvirons
  380.           ENDR
  381.